package com.ktgj.other.controller;

import com.ktgj.common.core.utils.StringUtils;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.other.common.RentCar;
import com.ktgj.other.domain.common.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@ControllerAdvice
@RestController
@RequestMapping("/rentCar")
public class RentCarController {
    @Autowired
    private RentCar rentCar;

    /**
     * 价格信息查询
     * @param request
     * @return
     */
    @PostMapping("/getDayPrice")
    public AjaxResult getDayPrice(@RequestBody DayPriceRequest request) {
        DayPriceResponse response = rentCar.getDayPrice(request);
        return AjaxResult.success(response);
    }

    /**
     * 下单接口
     * @param request
     * @return
     */
    @PostMapping("/createOrder")
    public AjaxResult createOrder(@RequestBody CreateOrderRequest request) {
        CreateOrderResponse response = rentCar.createOrder(request);
        return AjaxResult.success(response);
    }

    /**
     * 取消金额
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/orderCancelFee")
    public AjaxResult orderCancelFee(@RequestBody OrderCancelFeeRequest request) throws Exception {
        OrderCancelFeeResponse response = rentCar.orderCancelFee(request);
        return AjaxResult.success(response);
    }

    /**
     * 订单取消
     * @param request
     * @return
     */
    @PostMapping("/cancelOrderConfirm")
    public AjaxResult cancelOrderConfirm(@RequestBody CancelOrderConfirmRequest request) {
        CancelOrderResponse response = rentCar.cancelOrderConfirm(request);
        return AjaxResult.success(response);
    }

    /**
     * 订单查询
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/orderDetail")
    public AjaxResult orderDetail(@RequestBody OrderDetailRequest request) throws Exception {
        OrderDetailResponse response = rentCar.orderDetail(request);
        return AjaxResult.success(response);
    }

    /**
     * 根据地址获取经纬度
     * @param map
     * @return
     */
    @PostMapping("/getLatAndLngByAddress")
    public AjaxResult getLatAndLngByAddress(@RequestBody Map<?, ?> map) {
        if (StringUtils.isNotEmpty(map)) {
            String address = String.valueOf(map.get("address"));
            Map<String, Object> latAndLngByAddress = rentCar.getLatAndLngByAddress(address);
            return AjaxResult.success(latAndLngByAddress);
        } else {
            return AjaxResult.error("地址不能为空");
        }
    }
}
